home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / FORTH / FORTHMAC / OLD / TOOLS1 / !Forthmacs.extend.runtime < prev    next >
Text File  |  1996-06-12  |  5KB  |  139 lines

  1. \ portable RUNTIME PROFILER  Version 1.04 hs06.06.96
  2. \ USE:  -- runtime-profiling of colon definitions.
  3. \ mini manual:
  4. \ 1) load the cpu specific runtimer file, this file should be loaded automatically.
  5. \       fload extend\??cpu??\runtimer.fth
  6. \       fload extend\runtime.fth
  7. \ 2) From now on all colon definitions have an internal time measuring code part which is
  8. \       executed by calling the word.
  9. \ 3) Glossary:
  10. \ new ( -- )
  11. \       clear all timing information
  12. \ .times ( -- )
  13. \       display timing information
  14. \ profile ( -- ) name
  15. \       the word name is executed and the timing takes place. name could be a "benchmark" or
  16. \       the timing critical part of your application.       
  17. \ see   is patched, it will give correct information and knows about the timer information data
  18. \       structure
  19. \
  20. \ 4) example
  21. \ : test1       dup dup dup ;
  22. \ : test2       drop drop drop ;
  23. \ : test3       swap swap swap ;
  24. \ : test4       test1 test3 test2 test1 test3 test2 ;
  25. \ : test5       10000 0 do test4 test4 loop ;
  26. \ profile test5 .times
  27.  
  28. \
  29. \ User words of runtimer Version 1.0
  30. \       new (-- )             set all calls and ticks to 0
  31. \       .times ( -- )         print runtimes
  32. \       profile  name ( -- )  make a runtime profile of word name)
  33. \ Lit.  [1] "Laufzeitmessung von Forthworten", Bernd Pennemann, VD2/87
  34. \       [2] Formacs User's Guide, Mitch Bradley 
  35. \
  36. \ After loading the runtimer every colon definition is linked by an extra
  37. \ link-list for easy finding of all words.
  38.  
  39. \ Structure of new colon definition:
  40. \       timer-link-list long
  41. \       standard forthmacs header
  42. \       apf parameter field address of word
  43. \        0 (time
  44. \        4 calls
  45. \        8 #time
  46. \       12 compiled code continues ......
  47.  
  48. only forth also hidden also definitions  decimal
  49.  
  50. [ifdef]   profile                 \ this file shouldn't be compiled twice
  51.         ??cr .( runtimer already loaded) cr fexit
  52. [then]
  53.  
  54. [ifndef]  (time                   \ defined in cpu-specific file
  55.         ??cr .( runtimer needs cpu-specific timer definition-file first) cr fexit
  56. [then]
  57.  
  58. variable used-time
  59. variable timer-link             \ base of link-list bound to 0
  60.         here timer-link link!  0 ,
  61. defer scan-action               \ ( anf -- )
  62.  
  63. : scan-all      \ ( -- ) scan-action is done with all timer-linked words
  64.     timer-link
  65.     begin    link@ dup link@  exit? not and
  66.     while    dup cell+  l>name   scan-action
  67.     repeat    drop ;
  68.  
  69. : ticker-data   \ ( anf -- adr-timer adr-data )
  70.     name> >body cell+ dup cell+ swap ;
  71. : new-data      \ ( anf -- ) Call-nr und Time-nr  = 0
  72.     ticker-data off off  used-time off ;
  73. : legal-data    \ ( anf -- )
  74.     ticker-data drop @ 2-  used-time @ >
  75.     if used-time off then ;
  76. : .percent      \ ( n -- )
  77.     used-time @ dup 100000 >
  78.     if 100 / else swap 1005 * 10 / swap then /      ( n -- )
  79.     ?dup if 4 .r else ."  < 1" then ." %" ;
  80.  
  81. : .usec         \ ( usec -- )
  82.     dup 30000 >
  83.     if    499 +  1000 /  [char] m >r  dup 30000 >
  84.         if 499 +  1000 /  r> drop  bl >r  then
  85.     else    [char] u >r
  86.     then    ( n -- )
  87.     ?dup if 8 .r else ."        -" then  space r> emit  ." sec" ;
  88. : .one-data     \ ( anf -- ) prints data of one word
  89.     dup ticker-data @  swap @ swap
  90.     dup 0=  ( anf #time calls flag )
  91.     if 2drop drop exit then
  92.     rot .id  20 to-column
  93.     2dup   8 .r ."  Calls"    usec/tick * .usec
  94.     2dup swap usec/tick * swap /  .usec ." /call"
  95.     drop  used-time @
  96.     if  .percent else drop then ??cr ;
  97.  
  98. \ support for the decompiler
  99. [ifdef] see
  100.     : .runtime-info        ( ip -- ip' )
  101.         +indent .." \ <-- profiler-information available, "
  102.         cell+ dup @ .d ." calls, " cell+ dup @ .d ." ticks." cell+ -indent ;
  103.     : skip-runtime-info     ( ip -- ip' )
  104.         cell+ cell+ cell+ ;
  105.     ' (time ' .runtime-info  ' skip-runtime-info  install-decomp
  106. [then]
  107.  
  108. : (bye        remove-ticker (bye ;                
  109. : (forget       true abort" forget is not allowed with profiler loaded!" ;
  110. : (save-forth   true abort" save-forth is not allowed with profiler loaded!" ; 
  111.         ' (forget     ' forget >body token!
  112.         ' (save-forth ' save-forth >body token!
  113.         ' (bye is bye
  114. forth definitions
  115.  
  116. variable runtimer  runtimer off     \ on -> the runtimer code is compiled
  117. : new           \ ( -- ) set all ticks and calls to 0
  118.         ['] new-data is scan-action  scan-all ;
  119. : .times        \ ( -- ) prints data of all words
  120.         ??cr cr ." Runtime profiler V 1.03 (c) 1993,94 Hanno Schwalm"
  121.         cr #columns 0 do [char] _ emit loop cr cr
  122.         ['] legal-data is scan-action scan-all
  123.         ['] .one-data is scan-action
  124.         base @ >r decimal scan-all  r> base !
  125.         cr #columns 0 do [char] _ emit loop cr cr ;
  126.  
  127. : profile       \ name ( -- ) make runtime-profile of name
  128.         new '
  129.         get-ticks >r execute get-ticks r> -  used-time ! ;
  130.  
  131. : :             \ name ( -- ) redefined colon, using runtimer
  132.         runtimer @ 0= if :  exit then
  133.         timer-link link-here
  134.         :            \ make a colon definition
  135.         postpone (time 0 , 0 , ; immediate
  136.  
  137. only  forth also  definitions  decimal
  138. runtimer on
  139.